/*
 * File: startup-8051.c
 * 8051 startup file
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-10-24     LinuxLife    the first version
 * 2025-10-24     LinuxLife    fix putchar and getchar error
 */
#include "bsp.h"
#include "app.h"
#include <stdio.h>




/*
 * startup function
 */
void main(void)
{
    /* init board drivers */
    bsp_init();

    /* app sources without hardware */
    app_main_task();

    while(1);
}


/*
 * redefine libc uart input/output functions
 */
int putchar(int byte)
{
	SBUF = (char)byte;
	while(TI != 1);
	TI = 0;
	return (int)byte;
}

int getchar(void)
{
	while(!RI);
	RI = 0;
	return (int)SBUF;
}


/*
 * The interrupt functions of SDCC can only be defined in the file
 * where the main program is located.
 */
void int0_irq_handler(void)  __interrupt(0)
{
//    dev_int0_irq_handler();
}

void tim0_irq_handler(void)  __interrupt(1)
{
//    dev_tim0_irq_handler();
}

void int1_irq_handler(void)  __interrupt(2)
{
//    dev_int1_irq_handler();
}

void tim1_irq_handler(void)  __interrupt(3)
{
//    dev_tim1_irq_handler();
}

void uart1_irq_handler(void) __interrupt(4)
{
//    dev_uart1_irq_handler();
}